package com.me.mygdxgame;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector3;

public class GameOverScreen implements Screen {

	Texture againImage;
	Texture menuImage;
	Texture againClickImage;
	Texture menuClickImage;
	OrthographicCamera camera;
	Rectangle again;
	Rectangle menu;
	final Egg game;
	
	public GameOverScreen(final Egg ga) {
		// TODO Auto-generated constructor stub
		game = ga;
		camera = new OrthographicCamera();
		camera.setToOrtho(false, 800, 480);
		again = new Rectangle();
        again.x = 800/2 - 128;
        again.y = 480/2 + 128;
        again.width = 256;
        again.height = 64;
        
        menu = new Rectangle();
        menu.x = 800/2 - 50;
        menu.y = 480/2 - 50;
        menu.width = 100;
        menu.height = 29;
        
        
        again = new Rectangle();
        again.x = 800/2 - 90;
        again.y = 480/2 + 100;
        again.width = 180;
        again.height = 29;
        
        menuImage = new Texture(Gdx.files.internal("menu.png"));
        againImage = new Texture(Gdx.files.internal("playagain.png"));
        menuClickImage = new Texture(Gdx.files.internal("menuclick.png"));
        againClickImage = new Texture(Gdx.files.internal("playagainclick.png"));
        
	}
	@Override
	public void render(float delta) {
		// TODO Auto-generated method stub
		Gdx.gl.glClearColor(0, 0, 0.2f, 1);
        Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
        
        camera.update();
        game.batch.setProjectionMatrix(camera.combined);
        
        game.batch.begin();
        //game.font.draw(game.batch, "Start", start.x, start.y);
        game.batch.draw(againImage,again.x,again.y);
        game.batch.draw(menuImage,menu.x,menu.y);
        game.font.drawMultiLine(game.batch, "Your score : "+game.score, 290, 450);
        Vector3 vec = new Vector3();
    	vec.set(Gdx.input.getX(),Gdx.input.getY(),0);
		camera.unproject(vec);
        if(menu.contains(vec.x, vec.y))
        {
        	game.batch.draw(menuClickImage,menu.x,menu.y);
        }
        if(again.contains(vec.x, vec.y))
        {
        	game.batch.draw(againClickImage,again.x,again.y);
        }
        game.batch.end();

        if (Gdx.input.isTouched()) {
        	Vector3 vec2 = new Vector3();
        	vec2.set(Gdx.input.getX(),Gdx.input.getY(),0);
        	camera.unproject(vec2);
        	if(again.contains(vec2.x, vec2.y))
        	{
        		dispose();
        		game.setScreen(new GameScreen(game));
        	}
        	if(menu.contains(vec2.x, vec2.y))
        	{
        		dispose();
        		game.setScreen(new MainMenuScreen(game));
        	}
        }
	}

	@Override
	public void resize(int width, int height) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void show() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void hide() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub
	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub
		againImage.dispose();
		againClickImage.dispose();
		menuClickImage.dispose();
		menuImage.dispose();
	}

}
